<?php
//No direct access
defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
	<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
		<div id="mainownservice">
			<h3><?php echo JText::_('OWNSERVICE_REQUEST_APPROVEL'); ?></h3>
			<hr />
			<script language="javascript" type="text/javascript">
			<!--
				function submitbutton(pressbutton)
				{
					var form = document.adminForm;
					if (pressbutton == 'paidtransactions') {
						submitform( pressbutton );
						return;
					}
					/*if (form.timein.value == ''){
						alert( "<?php echo JText::_( 'OWNSERVICE_SELECT_TIME_TRANSFER', true ); ?>" );
					} else {*/
						submitform( pressbutton );
					/*}*/
				}
			//-->
			</script>
			<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm">
			<table cellspacing="10" cellpadding="0" border="0" width="100%">
				<?php /*<tr>
					<td>
						<fieldset>
							<legend><?php echo JText::_('OWNSERVICE_SELECT_TIME_TRANSFER'); ?></legend>
							<table class="admintable">
							<tr>
								<td>
									<span class="red">*</span> <?php echo $this->lists['time']; ?>
								</td>
							</tr>
							</table>
						</fieldset>
					</td>
				</tr> */ ?>
				<tr>
					<td>
						<table class="adminlist" cellspacing="10" cellpadding="0" border="0" width="100%">
							<thead>
								<tr>
									<th><?php echo JText::_( 'OWNSERVICE_RECEIVER_NO' ); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_ACCOUNT_NO' ); ?></th>
									<th><?php echo JText::_('OWNSERVICE_BANK_NAME'); ?></th>
									<th><?php echo JText::_('OWNSERVICE_BRANCH_CITY'); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_USER' ); ?></th>
									<th><?php echo JText::_('OWNSERVICE_CREATE_DATE'); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_AMOUNT_TRANSFER' ); ?><br />(AUD)</th>
									<th><?php echo JText::_( 'OWNSERVICE_RATE' ); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_TOTAL_EXCHANGE' ); ?></th>
									<?php /*<th><?php echo JText::_( 'OWNSERVICE_TRANSFER_ON' ); ?></th> */ ?>
								</tr>
							</thead>
							<tbody>
								<?php
								$priceformat = OwnserviceHelper::getParams('price_format', '#,###.##');
								$dateformat  = OwnserviceHelper::getParams('date_format', '%d/%m/%Y');
								$k=0;
								foreach ($this->rows as $row) :
									if (in_array($row->id, $this->cid)) :
								?>
								<tr class="<?php echo "row$k"; ?>">
									<td>
										<input type="hidden" name="cid[]" value="<?php echo $row->id; ?>" />
										<?php echo $row->invoice; ?>
									</td>
									<td><?php echo OwnserviceHelper::accountFormat($row->account); ?></td>
									<td><?php echo $row->bank_name; ?></td>
									<td><?php echo $row->branch_city; ?></td>
									<td><?php echo $row->username; ?></td>
									<td align="center"><?php echo JHTML::_('date', $row->created, $dateformat); ?></td>
									<td align="center"><?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); ?></td>
									<td align="right">
										<?php
											$color = '';
											if($row->extrarate > 0.00 ) {
												$color = 'red';
											} else if($row->extrarate < 0.00) {
												$color = 'green';
											}
										?>
											<?php if(!$row->iscore): ?>
											<div style="border-bottom: 1px solid;">
												<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th); ?> THB
											</div>
											<?php endif; ?>
											<div>
												<span class ="<?php echo $color; ?>"><?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate); ?></span>
												<?php echo $row->rate_code; ?> 
											</div>
									</td>
									<td align="right">
										<?php
											/*$color = '';
											$total = 0;
											if($row->extratotal > 0.00 ) {
												$color = 'red';
												$total = $row->extratotal;
											} else {
												$total = $row->amount * ($row->rate+$row->extrarate);
											}*/
										?>
											<?php if(!$row->iscore): ?>
											<div style="border-bottom: 1px solid;">
												<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th); ?> THB
											</div>
											<?php endif; ?>
											<div>
											<span class="<?php echo ($row->extratotal > 0.00?'red':''); ?>">
												<?php
													if($row->extratotal > 0.00 ) {
														echo OwnserviceHelper::moneyFormat($priceformat, $row->extratotal);
													} else {
														echo OwnserviceHelper::moneyFormat($priceformat, ( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee))); 
													}
												?>
											</span> <?php echo $row->rate_code; ?>
											</div>
									</td>
								<?php /*	<td align="center"><?php echo JHTML::_('date', $row->requested_date, $dateformat); ?></td> */ ?>
								</tr>
								<?php
									endif;
									$k = 1 - $k;
									endforeach;
								?>
							</tbody>
						</table>
					</td>
				</tr>
			</table>

			<div style="text-align:center; margin-top:5px;">
				<input type="button" name="confirm" onclick="submitbutton('approval');" value="<?php echo JText::_('OWNSERVICE_CONFIRM'); ?>" />
				<input type="button" name="cancel" onclick="javascript:submitbutton('paidtransactions');" value="<?php echo JText::_('OWNSERVICE_CANCEL');?>" />
			</div>

			<input type="hidden" name="option" value="com_ownservice" />
			<input type="hidden" name="task" value="" />
			<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
			<input type="hidden" name="controller" value="transaction" />
			<input type="hidden" name="view" value="transactions" />
			<?php echo JHTML::_( 'form.token' ); ?>
			</form>
	</div>
</div>